import axios from "axios";

const axiosInstance = axios.create({
    timeout: 30000  // 后台接口超时时间设置
})
//拦截器
axiosInstance.interceptors.request.use(config  => {

    return config;
},error => {
    console.log("请求拦截器：请求失败");
    //如果有then回调链，那么就断开直接结束。
    return Promise.reject(error);
})
axiosInstance.interceptors.response.use( response => {

    return response;
}, error=>{

    return Promise.reject(error);
});

export function request(url,method="GET",data= {},headers = {
    "Content-Type":"application/json"
}) {
    let baseURL = "";
    return axiosInstance.request({
        url,
        baseURL,
        method,
        data,
        headers
    })
}